# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: Pablo Correa Gomez <ablocorrea@hotmail.com>
pkgname=gnome-software
pkgver=41.5
pkgrel=0
pkgdesc="Software lets you install and update applications and system extensions"
url="https://wiki.gnome.org/Apps/Software"
# s390x and riscv64 blocked by polkit
arch="all !s390x !riscv64"
license="GPL-2.0-or-later"
makedepends="meson appstream-dev gdk-pixbuf-dev libxmlb-dev glib-dev gtk+3.0-dev
	json-glib-dev libsoup-dev gspell-dev polkit-dev gtk-doc ostree-dev
	flatpak-dev libgudev-dev libhandy1-dev gsettings-desktop-schemas-dev"
options="!check" # lots of failing tests
install="$pkgname.post-upgrade"
subpackages="$pkgname-lang $pkgname-doc $pkgname-dbg
	$pkgname-dev $pkgname-lib $pkgname-plugin-flatpak:flatpak_plugin"
source="https://download.gnome.org/sources/gnome-software/${pkgver%.*}/gnome-software-$pkgver.tar.xz
	0001-gs-external-appstream-utils-use-external-appstream-s.patch
	0002-gs-external-appstream-utils-hash-url-to-allow-same-b.patch
	0003-lib-cleanup-public-headers-and-mark-gs-test.h-as-pub.patch
	org.gnome.software.gschema.override
	"

case "$CARCH" in
	x86|x86_64|aarch64|armv7) makedepends="$makedepends fwupd-dev" ;;
esac

build() {
	case "$CARCH" in
		x86|x86_64|aarch64|armv7) conf="-Dfwupd=true" ;;
		*) conf="-Dfwupd=false" ;;
	esac


	abuild-meson \
		-Dvalgrind=false \
		-Dmalcontent=false \
		-Dpackagekit=false \
		-Dexternal_appstream=true \
		$conf \
		. output
	meson compile ${JOBS:+-j ${JOBS}} -C output
}

check() {
	meson test --no-rebuild -v -C output
}

package() {
	depends="gnome-software-plugin-apk"
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
	mkdir -p "$pkgdir"/usr/share/glib-2.0/schemas/
	sed "s|@CARCH@|$CARCH|g" "$srcdir"/org.gnome.software.gschema.override > \
		"$pkgdir"/usr/share/glib-2.0/schemas/org.gnome.software.gschema.override
}

dev() {
	default_dev

	amove usr/lib/gnome-software/libgnomesoftware.so
}

lib() {
	pkgdesc="$pkgdesc (shared library)"
	depends=""

	amove usr/lib/gnome-software/libgnomesoftware.so.*
}

flatpak_plugin() {
	pkgdesc="$pkgdesc (flatpak plugin)"
	install_if="$pkgname=$pkgver-r$pkgrel flatpak"
	depends=""

	amove usr/lib/gnome-software/plugins-16/libgs_plugin_flatpak.so
	amove usr/share/metainfo/org.gnome.Software.Plugin.Flatpak.metainfo.xml
}

sha512sums="
60701d50dd8e7fa01c05c8ee7823b053d40b0fa145419601ece732827527d4d7ae9af178b5b6622ac4d729d3d430c14981a2fd4b0f086dd6d05a49fd507f2cb6  gnome-software-41.5.tar.xz
52e4f99a4e1e2e688b1dcb146bcad3f3ba0e804af841d3837de5a7905f90689dc6258e625476a5fa402e8cfb5f7b814f3bdb0cf0dfab5ca8ebbf6193099e9916  0001-gs-external-appstream-utils-use-external-appstream-s.patch
467e023cc953f1d7caf83a4087f7f6311f64d20da32dafb2a97bd7488bb597e2d407d1166937c1776c0add199508ac45f361d7754687f638e518dbfaa8f80c6e  0002-gs-external-appstream-utils-hash-url-to-allow-same-b.patch
4f3248916d8d15753dc22580e71a37cbfd42bb81ee0befcc51cbbbc5ce8a6573be9dae8d049c9c10fbdcf6292b83fda0d2175d1f6554e7ee8f08024ce6bdffe9  0003-lib-cleanup-public-headers-and-mark-gs-test.h-as-pub.patch
dc83eba4b5da759b6bc72d0f30ba4e9338684eb0d32d3e2b7989341ee6f8efc15b09dda88d1dc3cc6a2de0a2ae22a41c2fdbfe352b5d7c7ecff44c2d6035e17f  org.gnome.software.gschema.override
"
